import { createApp } from "vue";
import TimeLine from "@/components/TimeLine";
import CopyCode from "@/components/CopyCode";
import { MessageEventListener } from "@/utils/functions";
import router from "./router";
import App from "./App.vue";
import MatDesignUI from "~/index";
import "~/styles/index.less";

/* import MatDesignUI from "../lib"; // 测试
import "../lib/styles/index.css"; // 测试 */

const app = createApp(App);
app.component(TimeLine.name, TimeLine);
app.component(CopyCode.name, CopyCode);
app.use(MatDesignUI);
app.use(router);
app.mount("#root");

MessageEventListener((path) => {
  if (!path.includes("/")) return;
  const routePath = app.config.globalProperties.$route.path;
  const { $router } = app.config.globalProperties;
  if (path === "/") {
    routePath !== "/doc/introduce" &&
      $router.push({
        path: "/doc/introduce"
      });
  } else if (path.includes("/doc") && routePath !== path) {
    $router.push({
      path
    });
  }
}, true);
